#!/usr/bin/python

from ftplib import FTP

rir_names = ['arin', 'ripe', 'afrinic', 'apnic', 'lacnic']

for name in rir_names:
	print name
	ftp = FTP()
	ftp.connect('ftp.'+name+'.net', 21)
	ftp.login()
	filename = ''
	if name == 'ripe':
		ftp.cwd('ripe/stats/')
		filename = 'delegated-ripencc-latest'
	else:
		ftp.cwd('pub/stats/'+name+'/')
		filename = 'delegated-'+name+'-latest'
	file_handler = open(filename, 'wb')
	ftp.retrbinary('RETR '+filename, file_handler.write)
	file_handler.close()
	ftp.quit()
